from django.views.generic import DetailView

from app.models import Studiengang, Modulgruppe, Modul, Modulbaustein


class ModulDetailView(DetailView):
    context_object_name = "modul"
    model = Modul

    def get_context_data(self, **kwargs):
        context = super(ModulDetailView, self).get_context_data(**kwargs)
        baustein_list = Modulbaustein.objects.filter(modul__id=self.object.id).order_by('titel')
        context['baustein_list'] = baustein_list
        return context
        
        
class StudiengangDetailView(DetailView):

    context_object_name = "studiengang"
    model = Studiengang
    
    def get_context_data(self, **kwargs):
        context = super(StudiengangDetailView, self).get_context_data(**kwargs)
        modulgruppe_list = Modulgruppe.objects.select_related("modul_set").order_by('name', 'modul__titel')
        #modul_list = Modul.objects.filter(modulgruppe__studiengang=self.object.id).order_by('-modulgruppe__name', 'titel')
        context['modulgruppe_list'] = modulgruppe_list
        return context

